package com.briup.mt.web.controller;

import com.briup.mt.bean.Dataset;
import com.briup.mt.service.IDatasetService;
import com.briup.mt.utils.Message;
import com.briup.mt.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author wyq
 * @create 2020-12-16 18:52
 */
@RestController
@Api(description = "数据集管理")
@Validated
@RequestMapping("/dataset")
public class DatasetController {
    @Autowired
   private IDatasetService datasetService;

    @ApiOperation("查询")
    @GetMapping("query")
    public Message query(String name) {
        List<Dataset> list = datasetService.query(name);
        return MessageUtil.success(list);
    }

    @ApiOperation("保存或更新")
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Dataset dataset) {
        datasetService.saveOrUpdate(dataset);
        return MessageUtil.success("操作成功");
    }

    @ApiOperation("删除")
    @DeleteMapping("deleteById")
    public Message deleteById(@RequestParam @NotNull long id) {
        datasetService.deleteById(id);
        return MessageUtil.success("删除成功");
    }
}
